<?php
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/user/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/mblog/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/album/inc.php");


//所有的参数
$g_cgival 	= array();
//存储中间数据 非输出数据 可以不用
$g_pro	 	= array();
//要显示的数据 输出数据
$g_show 	= array();

function check_cgi_pro()
{		
	global $g_cgival, $g_pro, $g_show, $config;
	
	cgi::both($g_cgival["p"], "p", "");
	$g_cgival["p"] = intval($g_cgival["p"]);
	
	if($g_cgival["p"] < 1) $g_cgival["p"]=1;
	
	cgi::both($g_cgival["uid"], "uid", "");
	$g_cgival["uid"] = intval($g_cgival["uid"]);
	
	cgi::both($g_cgival["pcount"], "pcount", 12);
	$g_cgival["pcount"] = intval($g_cgival["pcount"]);
	
}


function get_data()
{
	global $g_cgival, $g_pro, $g_show, $config;
	
	
	$g_show["user_top_type"] = "my_album";
	
	$g_show["hide_shadow"] = true;
	$g_show["uid"] = $album_uid = $g_cgival["uid"];
	$g_show["pcount"] = $pcount = $g_cgival["pcount"];
	
	
	$mblog_cache_v2 = new mblog_cache_v2();
	$mblog_user_info = $mblog_cache_v2->cache_api_get_user_info_by_uid($album_uid);
	$g_show["mblog_user_info"] = $mblog_user_info["data"]["result"];
	//登录相关
	$user_info = new user_info();
	$g_show["user_info"] = $user_info->get_user_info_by_uid($album_uid);
	$db_album_info = new db_album_info();
	
	
	$is_login = $user_info->is_logined();
	if($is_login)
	{
		$user_detail_info = $user_info->get_cur_user_info();
		$g_show["is_logined"] = true;
		$g_show["current_user_info"] = $user_detail_info;
	}
	
	
	$list = $db_album_info->get_album_list_by_uid($album_uid,$g_cgival["p"],$g_cgival["pcount"]);
	$count = $db_album_info->get_album_count_by_uid($album_uid);
	
	if($list)
	{
		$uid_array = array();	
		foreach($list as $value)
		{
			$uid_array[] = $value["create_uid"];
			
		}
		
		$db_user_info = new db_user_info();
		$user_info = $db_user_info->get_user_list_by_uids($uid_array);
		
		$user_info_array = array();
		foreach($user_info as $key => $value)
		{
			$user_info_array[$value["uid"]]=$value;
			
		}
		
		foreach($list as $key => $value)
		{
			$list[$key]["pic1"] = str_replace("/bmiddle/","/thumb300/",$list[$key]["pic1"]) ;
			$list[$key]["pic2"] = str_replace("/bmiddle/","/square/",$list[$key]["pic2"]) ;
			$list[$key]["pic3"] = str_replace("/bmiddle/","/square/",$list[$key]["pic3"]) ;
			$list[$key]["pic4"] = str_replace("/bmiddle/","/square/",$list[$key]["pic4"]) ;
			
			$list[$key]["user_info"] =$user_info_array[$value["create_uid"]]  ;
		}
		
	}
		
	
	$g_show["count"] = $count;
	$g_show["list"] = $list;
	
	
	
	$g_show["page_title"] = "{$g_show["user_info"]["user_nickname"]}的专辑" ;
	$g_show["page_keywords"] = "{$g_show["user_info"]["user_nickname"]}的专辑" ;
	$g_show["page_desc"] = "{$g_show["user_info"]["user_nickname"]}的 专辑" ;
	
	$mod_mblog = new mod_mblog();
	list($list1,$list2,$list3,$list4) = $mod_mblog->get_topic_list_order_by_like();
	$g_show["list1"] = $list1;
	$g_show["list2"] = $list2;
	$g_show["list3"] = $list3;
	$g_show["list4"] = $list4;
	
	
	$Pages = new Pages($g_show["count"],$g_cgival["p"],$g_cgival["pcount"]);
	$g_show["page_bar"] = $Pages->getLinks("?uid={$g_cgival["uid"]}&p=",8);
}

try {
	$g_show['error'] = 0;
	$g_show['errmsg'] = "";
	check_cgi_pro();
	get_data();
	
} catch (Exception $e) {
	$g_show['error'] = 1;
	$g_show['errmsg'] = $e->getMessage();
}

show_pro();


exit;

function show_pro()
{
	global $g_cgival, $g_pro, $g_show, $config;

	$smarty = p_get_smarty();	
	$smarty->assign("g_show", $g_show);
	if (isset($_GET["debug"]))
	{
		print_r($g_show);
	}
	$smarty->display("user/huaban_user_album.html");
	
	unset($g_cgival);
	unset($g_pro);
	unset($g_show);
	unset($config);
	
}

